#ifndef DEVICE
#define DEVICE

#include "icone.h"
#include "device_stub.h"
#include "../../define.h"
#include "../../texture/texture.h"
#include "../os/cpuid.h"
#include "../os/gpuid.h"
#include "../os/ppuid.h"
#include "event.h"

namespace sleek
{
    namespace core
    {
        namespace device
        {
            enum DeviceWindowManager
            {
                DWM_AUTO,
                DWM_SDL,
                DWM_X11,
                DWM_XF86,
                DWM_WIN,
//                DWM_WXWIDGET,
//                DWM_GLUT,
//                DWM_GTK,
//                DWM_QT,
                DWM_COUNT
            };
            enum GL_RENDER_CONTEXT
            {
                GRC_0,
                GRC_1,
                GRC_2,
                GRC_3,
                GRC_COUNT
            };
            class Device
            {
                public:
                    Device(Device_stub);
                    virtual ~Device();

                    virtual bool testGlError();
                    virtual void setGamma(texture::pixel);
                    virtual void setCaption(os::stringc);
                    virtual void setEventReceiver(event*);
                    virtual void setVideoSize(math::vector2du);
                    virtual void setWindowPos(math::vector2di);
                    virtual void setFullScreen(bool);

                    virtual void enableAntialiasing(DeviceAntiailiasingMode);
                    virtual void enableWindowDecorator(bool);
                    virtual void centerWindowPos();

                    virtual void makeRenderContext(GL_RENDER_CONTEXT);
                    virtual void destroyRenderContext(GL_RENDER_CONTEXT);
                    virtual void switchToRenderContext(GL_RENDER_CONTEXT);
                    virtual GL_RENDER_CONTEXT getCurrentRenderContext();
                    virtual core::math::vector2du getDesktopVideoSize();

                    virtual u32 getFPS();
                    virtual Device_stub getInfo();
                    virtual event* getEventReceiver();
                    virtual input* getCurrentEvent();
                    virtual texture::texture* createScreeshot();

                    virtual os::cpuid* getProcessorCentral();
                    virtual os::gpuid* getProcessorGraphics();
                    virtual os::ppuid* getProcessorPhysics();
                    virtual void WarpMouse(math::vector2di);
                    virtual void ShowMouse(bool);
                    virtual void WriteConfig(core::os::stringc);

                    virtual bool run();
                    virtual void exit();
                    virtual bool ready();
                    virtual bool manage();
                    virtual void begin(texture::pixel clearcolor = texture::pixel(128,255,255));
                    virtual void end();

                    virtual cl::Context *getOpenCL();
                protected:
                    Device();

                    u32 fps, stack;
                    event *evt, *ext;
                    Device_stub info;
                    math::timer *tm;
                    input* current;

                    bool running, reading;
                    GL_RENDER_CONTEXT glcurrent;
                    cl::Context *ocl;

                    os::cpuid *cpu; os::gpuid *gpu; os::ppuid *ppu;
                    void welcomeMessage();

                    virtual void initOpenCL();
                    virtual void initOpenGL();
                    virtual bool checkOpenGLExtension(const char*);
                private:
                    friend Device* CreateDeviceWindowManager(DeviceWindowManager, Device_stub);
            };
            Device* CreateDeviceWindowManager(DeviceWindowManager, Device_stub);
        }
    }
}
#endif

